<?php 

namespace App\Http\Controllers\Admin;

use Session,Redirect;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Admin\ThrottlesLogins;
use Illuminate\Foundation\Admin\AuthenticatesAndRegistersUsers;
use DB;
class LoginController extends Controller
{
   public function login(){
   		$new = new \App\Admin();
   		if(empty($_POST)){
			return view('Admin.Login.login');
		}else{
			$admin_name = $_POST["username"];
			$admin_password = md5($_POST["password"]);
			//dd($admin_password);
			$code = $_POST["captcha"];
			if(Session::get('milkcaptcha')!=$code) {  
               return "<script>alert('验证码有误！！！');location.href='login'</script>"; 
            }   
			$adminOne = $new->getOnes($admin_name);
			//dd($adminOne->admin_password);
			if(empty($adminOne)){
				return "<script>alert('用户名输入有误，请重新输入！！！');location.href='login'</script>";
			}else{
				if($adminOne->admin_password != $admin_password){
					return "<script>alert('密码不正确，请重新输入！！');location.href='login'</script>";
				}else{
					Session::set('admin_name',$adminOne->admin_name);
					Session::set('admin_id',$adminOne->admin_id);
					$data = ['login_num'=>$adminOne->login_num+1,'last_login_time'=>time()];
					$loginDataUpdate = $new->login_up($data,$adminOne->admin_id);
					return redirect('admin/index');
				}
			}
		}
   }

   	//退出
	public function login_out(){
		Session::flush();
		return "<script>alert('退出成功！！');location.href='login'</script>";
	}





}



 ?>

